package com.scenic.user.service.controller;

import com.common.Result;
import com.model.dto.LoginDto;
import com.model.dto.RegisterDto;
import com.model.entity.SysUser;
import com.model.vo.LoginVo;
import com.scenic.user.service.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户服务")
@RestController
@RequestMapping(value = "/user/system/")
public class IndexController {

    @Autowired
    private SysUserService sysUserService ;

    @ApiOperation(value = "用户登录")
    @ApiImplicitParam(name = "loginDto", value = "登录参数", required = true, dataType = "LoginDto")
    @PostMapping(value = "/login")
    public Result<LoginVo> login(@RequestBody LoginDto loginDto) {
        LoginVo loginVo = sysUserService.login(loginDto) ;
        return Result.ok(loginVo) ;
    }

    @ApiOperation(value = "用户注册")
    @PostMapping(value = "/register")
    public Result<String> register(@RequestBody RegisterDto registerDto) {
        sysUserService.register(registerDto) ;
        return Result.ok("注册成功") ;
    }

    @ApiOperation(value = "获取用户信息")
    @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "String", paramType = "path")
    @GetMapping(value = "/{userId}")
    public Result<SysUser> getUserInfo(@PathVariable String userId) {
        SysUser userInfo = sysUserService.getUserInfo(userId);
        return Result.ok(userInfo);
    }
}
